package user

import (
	"context"
	"fmt"
	"strconv"

	"go-admin/base/internal/svc"
	"go-admin/base/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type InfosLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewInfosLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfosLogic {
	return &InfosLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *InfosLogic) Infos(req *types.UserBaseReqDTO) (resp *types.UserRespDTOSS, err error) {
	// todo: add your logic here and delete this line
	fmt.Println(req.Token + "--------")
	userId, err := strconv.ParseInt(req.Token, 10, 64)
	if err != nil {
		fmt.Errorf(err.Error())
		return nil, err
	}
	user, err := l.svcCtx.UserModel.FindOne(l.ctx, userId)
	if err != nil {
		fmt.Errorf(err.Error())
		return nil, err
	}
	return &types.UserRespDTOSS{
		Data: types.UserRespDTO{
			UserID:   user.Id,
			UserName: user.UserName.String,
			UserNum:  user.UserNum.String,
		},
		Result: types.Result{
			Code: 200,
		},
	}, nil
}
